package com.example.mobile2021606185zhn0401;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView tvMainTitle;
    private ImageView ivMainLight;
    private Button btnMainLightOn;
    private Button btnMainLightoff;
    private Button btnMainFanOnOff;
    private Button btnNext;

    private boolean fanStatus = false;

    private int[] lines;
    private int linesID = 0;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();


        btnNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                lines = new int[6];
                lines[0] = R.drawable.line01_01;
                lines[1] = R.drawable.line02_02;
                lines[2] = R.drawable.line03s_03;
                lines[3] = R.drawable.line04_04;
                lines[4] = R.drawable.line05_05;
                lines[5] = R.drawable.line06_06;

                ivMainLight.setImageResource(lines[linesID + 1]);
                linesID += 1;
            }
        });

        btnMainLightOn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ivMainLight.setImageResource(R.drawable.light_on);
            }
        });
        btnMainLightoff.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ivMainLight.setImageResource(R.drawable.light_off);
            }
        });
        btnMainFanOnOff.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (fanStatus) {
                    ivMainLight.setImageResource(R.drawable.fan_off);
                    fanStatus = false;
                } else {
                    ivMainLight.setImageResource(R.drawable.fan_on);
                    fanStatus = true;
                }
            }
        });
    }

    private void initView() {
        tvMainTitle = (TextView) findViewById(R.id.tv_main_title);
        ivMainLight = (ImageView) findViewById(R.id.iv_main_light);
        btnMainLightOn = (Button) findViewById(R.id.btn_main_lightOn);
        btnMainLightoff = (Button) findViewById(R.id.btn_main_lightoff);
        btnMainFanOnOff = (Button) findViewById(R.id.btn_main_Fan_on_off);
        btnNext = (Button) findViewById(R.id.btn_next);
    }
}